<template>
  <view class="index">
    <view class="center">
      <view class="ind_from">
        <view class="row">
          <view class="label">收缩压(毫米汞柱)</view>
          <view class="value">
            <input
              class="input"
              v-model="formData.shousuo"
              type="number"
              placeholder="请输入收缩压"
            />
          </view>
        </view>
        <view class="row">
          <view class="label">舒张压(毫米汞柱)</view>
          <view class="value">
            <input
              class="input"
              v-model="formData.shuzhang"
              type="number"
              placeholder="请输入舒张压"
            />
          </view>
        </view>
        <view class="row">
          <view class="label">脉搏(次/分)</view>
          <view class="value">
            <input
              class="input"
              v-model="formData.maibo"
              type="number"
              placeholder="请输入脉搏"
            />
          </view>
        </view>
        <view class="row">
          <view class="label">时间</view>
          <view class="value">
            {{ formData.time }}
          </view>
        </view>
      </view>
      <view class="btn" @click="submit">添加</view>
      <view v-if="showResult" class="result">
        <view v-for="(item, index) in recordList" :key="index" class="ind_from">
          <view class="row">
            <view class="label">收缩压(毫米汞柱)</view>
            <view class="value">
              {{ item.shousuo }}
            </view>
          </view>
          <view class="row">
            <view class="label">舒张压(毫米汞柱)</view>
            <view class="value">
              {{ item.shuzhang }}
            </view>
          </view>
          <view class="row">
            <view class="label">脉搏(次/分)</view>
            <view class="value">
              {{ item.maibo }}
            </view>
          </view>
          <view class="row">
            <view class="label">时间</view>
            <view class="value">
              {{ formData.time }}
            </view>
          </view>
        </view>
      </view>
      <view class="pub_ad_banner">
        <!-- #ifdef MP-TOUTIAO -->
        <ad
          :unit-id="adBannerIdDouyin"
          :ad-intervals="30"
          :fixed="false"
          type="banner"
          scale="100"
        />
        <!-- #endif -->
        <!-- #ifdef MP-KUAISHOU -->
        <ad :type="100011054" :unit-id="adBannerIdKuaishou"></ad>
        <!-- #endif -->
      </view>
    </view>
  </view>
</template>

<script>
import {
  showAdConfirmModal,
  adVideoCreate,
  adVideoShow,
  adBannerIdDouyin,
  adBannerIdKuaishou,
} from "@/common/ad";
export default {
  data() {
    return {
      adBannerIdDouyin: adBannerIdDouyin,
      adBannerIdKuaishou: adBannerIdKuaishou,
      showResult: false,
      recordList: [],
      isUnlock: false,
      formData: {
        shousuo: "",
        shuzhang: "",
        maibo: "",
        time: "",
      },
      result: {
        total: "",
      },
    };
  },
  onLoad() {
    adVideoCreate();
    var now = new Date();
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var date = now.getDate();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds();
    this.formData.time =
      year +
      "-" +
      month +
      "-" +
      date +
      " " +
      hours +
      ":" +
      minutes +
      ":" +
      seconds;
  },
  methods: {
    changeTime(e) {
      this.formData.time = e;
    },
    record() {
      this.recordList.push(this.formData);
    },
    getResult() {
      this.record();
      this.isUnlock = true;
      this.showResult = true;
    },
    submit() {
      if (this.formData.shousuo == "") {
        this.global.toast("请输入收缩压");
        return;
      }
      if (this.formData.shuzhang == "") {
        this.global.toast("请输入舒张压");
        return;
      }
      if (this.formData.maibo == "") {
        this.global.toast("请输入脉搏");
        return;
      }
      if (!this.isUnlock) {
        showAdConfirmModal(() => {
          try {
            adVideoShow(() => {
              this.getResult();
            });
          } catch (error) {
            this.getResult();
          }
        });
      } else {
        this.getResult();
      }
    },
  },
};
</script>

<style scoped lang="scss">
.banner {
  display: block;
  width: 100%;
}
.pub_radio {
  position: relative;
  padding-left: 50rpx;
}
.pub_radio:before {
  position: absolute;
  top: 50%;
  margin-top: -20rpx;
  left: 0;
  content: "";
  width: 40rpx;
  height: 40rpx;
  background-image: url("@/static/img/checked.png");
  background-size: cover;
}
.pub_radio.active:before {
  background-image: url("@/static/img/checked_active.png");
  background-size: cover;
}
.ind_from {
  background: #f9f5ef;
  margin-top: 20rpx;
  border: 4rpx solid #b39569;
  border-radius: 10rpx;
  .row {
    padding: 16rpx 20rpx;
    display: flex;
    border-bottom: 1px solid #ccc;
    &:last-child {
      border-bottom: 0;
    }
    .label {
      width: 170px;
      flex-shrink: 0;
    }
    .value {
      width: 100%;
      .input {
        width: 100%;
      }
    }
    .pub_radio {
      display: inline-block;
      margin-right: 40rpx;
    }
  }
}
.btn {
  margin-top: 30rpx;
  background: #db0000;
  color: #fff;
  text-align: center;
  padding: 14rpx 0;
  border-radius: 10rpx;
}
.sub_text {
  text-align: center;
  padding-top: 30rpx;
  font-size: 24rpx;
  color: #666;
  .red {
    color: red;
  }
  .bold {
    font-weight: bold;
  }
}
.pub_ad_banner {
  margin-top: 30rpx;
}
.result {
  background: #f9f5ef;
  margin-top: 10px;
  padding: 10px 10px;

  .ind_from {
    font-size: 16px;
  }

  .left,
  .right {
    width: 100%;
    padding: 10px 10px;
    background: #6f6fff;
    color: #fff;
  }

  .left {
    margin-right: 10px;
  }

  .p {
    display: block;

    .strong {
      font-size: 30px;
      display: inline-block;
      margin-right: 6px;
    }
  }

  .title {
    text-align: center;
    font-size: 30px;
  }
  .desc {
    font-size: 32px;
    text-align: center;
    color: #ff1afe;
  }
}
</style>